package main;

import gui.MainWindow;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;

public class Main {

	private static Main instance = null;
	private Properties properties = new Properties();
	private Properties configuration;
	private String mmls;
	private String fls;
	private String img_cat;
	private String ils;
	private String ifind;
	private String blkcalc;
	private String blkcat;
	private String blkls;
	private String blkstat;
	private String fcat;
	private String ffind;
	private String fsstat;
	private String hfind;
	private String icat;
	private String img_stat;
	private String istat;
	private String jcat;
	private String jls;
	private String mactime;
	private String mmcat;
	private String mmstat;
	private String tsk_comparedir;
	private String tsk_gettimes;
	private String tsk_loaddb;
	private String tsk_recover;
	private String fileSeperator = System.getProperty("file.separator");
	private String configFileName = "sleuthkit-gui.config";
	private MainWindow mainWindow;

	public Main(String[] args) {
		// TODO Auto-generated constructor stub
		if (args.length<1){
			
			for (String arg : args) {
				arg=arg.toLowerCase();
				if (arg.startsWith("--config=") || arg.startsWith("-c=")){
					properties.setProperty("config", arg.split("=")[1]);
				} else {
					printHelp();
				}
			}
		}
	}

	private void printHelp() {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		instance  = new Main(args);
		// read config files, its a java properties file
		instance.setup();
		instance.createGui();
	}

	/**
	 * Main method for handling the creation of the GUI.
	 * Responsible for the main flow of the GUI.
	 * 
	 */
	private void createGui() {
		// TODO Auto-generated method stub
		mainWindow = new MainWindow();
		mainWindow.setup();
	}

	private void setup() {
		try {
			configuration.loadFromXML(new FileInputStream(properties.getProperty(configFileName ,
					System.getProperty("user.home")+
					fileSeperator+".sleuthkit-gui"+fileSeperator+ configFileName)));
		} catch (InvalidPropertiesFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.exit(1);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.exit(2);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.exit(3);
		}
		
		mmls=configuration.getProperty("mmls");
		fls =configuration.getProperty("fls");
		blkcalc = configuration.getProperty("blkcalc");
		blkcat = configuration.getProperty("blkcat");
		blkls = configuration.getProperty("blkls");
		blkstat = configuration.getProperty("blkstat");
		fcat = configuration.getProperty("fcat");
		ffind = configuration.getProperty("ffind");
		fls = configuration.getProperty("fls");
		fsstat = configuration.getProperty("fsstat");
		hfind = configuration.getProperty("hfind");
		icat = configuration.getProperty("icat");
		ifind = configuration.getProperty("ifind");
		ils = configuration.getProperty("ils");
		img_cat = configuration.getProperty("img_cat");
		img_stat = configuration.getProperty("img_stat");
		istat = configuration.getProperty("istat");
		jcat = configuration.getProperty("jcat");
		jls = configuration.getProperty("jls");
		mactime = configuration.getProperty("mactime");
		mmcat = configuration.getProperty("mmcat");
		mmls = configuration.getProperty("mmls");
		mmstat = configuration.getProperty("mmstat");
		tsk_comparedir = configuration.getProperty("tsk_comparedir");
		tsk_gettimes = configuration.getProperty("tsk_gettimes");
		tsk_loaddb = configuration.getProperty("tsk_loaddb");
		tsk_recover = configuration.getProperty("tsk_recover");
		
		
	}

}
